package com.whzykj.ctrl;

import java.util.HashMap;
import java.util.Map;

import com.jfinal.core.Controller;
import com.jfinal.kit.HashKit;
import com.jfinal.plugin.activerecord.Page;
import com.whzykj.common.DateUtil;
import com.whzykj.common.SystemRunParamCache;
import com.whzykj.model.Station;
import com.whzykj.model.SystemRunParam;
import com.whzykj.model.Userinfo;

public class RunparamController extends Controller{
	/**
	 * 进入到运行参数列表页面
	 */
	public void index(){
		this.renderJsp("/admin/auth/runparamList.jsp");
	}
	
	/**
	 * 显示所有运行参数列表
	 */
	public void list(){
		Integer page = this.getParaToInt("page");
		Integer rows = this.getParaToInt("rows");
		
		Map map=null;
		try {
			String sqlBefore = " select * ";
			StringBuffer sqlAfter = new StringBuffer(
					" from system_run_param ");
			Page<SystemRunParam> paginate = SystemRunParam.me.paginate(page, rows, sqlBefore,
					sqlAfter.toString());
			map = new HashMap();
			map.put("rows", paginate.getList());
			map.put("total", paginate.getTotalRow());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		this.renderJson(map);
	}
	
	/**
	 * 更新参数的值
	 */
	public void update(){
		Integer id = this.getParaToInt("id");
		String value = this.getPara("value");
		SystemRunParam param=SystemRunParam.me.findById(id);
		param.set("value", value);
		param.set("update_time", DateUtil.getNow());
		boolean update = false;
		try {
			update = SystemRunParam.me.updateParam(param);
//			System.out.println("hello:"+SystemRunParamCache.cache.getParamValue(param.getStr("name")));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		this.renderText(update ? "1" : "0");
	}
}
